package com.systop.asset.controller;

import com.systop.asset.entity.RestResponse;
import com.systop.asset.service.IAssetService;
import com.systop.asset.service.IInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>ClassName : StatisticController</p>
 * <p>Description : </p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2025/7/15 13:38
 */
@RestController
@RequestMapping("/system/statistic")
public class StatisticController {

    @Autowired
    private IAssetService assetService;

    @Autowired
    private IInventoryService inventoryService;

    /**
     * 根据状态统计资产信息
     * @return
     */

    /**
     * 获取资产状态统计数据（包含数量和占比）
     * @return 资产状态统计结果
     */
    @GetMapping("/assetStatusStats")
    public RestResponse<?> getAssetStatusStats() {
        try {
            List<Map<String, Object>> statistics = assetService.getAssetStatusStatistics();
            return RestResponse.success(statistics);
        } catch (Exception e) {
            return RestResponse.failure(500, "获取资产状态统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取资产分类统计数据
     * @return 资产分类统计结果
     */
    @GetMapping("/assetCategoryStats")
    public RestResponse<?> getAssetCategoryStats() {
        try {
            List<Map<String, Object>> statistics = assetService.getAssetCategoryStatistics();
            return RestResponse.success(statistics);
        } catch (Exception e) {
            return RestResponse.failure(500, "获取资产分类统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取部门资产统计数据
     * @return 部门资产统计结果
     */
    @GetMapping("/assetDeptStats")
    public RestResponse<?> getAssetDeptStats() {
        try {
            List<Map<String, Object>> statistics = assetService.getAssetDeptStatistics();
            return RestResponse.success(statistics);
        } catch (Exception e) {
            return RestResponse.failure(500, "获取部门资产统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取位置资产统计数据（包含数量和占比）
     * @return 位置资产统计结果
     */
    @GetMapping("/assetLocationStats")
    public RestResponse<?> getAssetLocationStats() {
        try {
            List<Map<String, Object>> statistics = assetService.getAssetLocationStatistics();
            return RestResponse.success(statistics);
        } catch (Exception e) {
            return RestResponse.failure(500, "获取位置资产统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取库存预警信息
     * @return 库存预警结果
     */
    @GetMapping("/inventoryWarning")
    public RestResponse<?> getInventoryWarning() {
        try {
            List<Map<String, Object>> warnings = inventoryService.getInventoryWarningList();
            return RestResponse.success(warnings);
        } catch (Exception e) {
            return RestResponse.failure(500, "获取库存预警失败: " + e.getMessage());
        }
    }
}
